//
//  MyCancleSureAlertView.m
//  NtoccShipper
//
//  Created by mac on 2019/12/20.
//  Copyright © 2019 zhuchongjin. All rights reserved.
//

#import "MyCancleSureAlertView.h"
#import "UITextView+Placeholder.h"

#define MyInPutViewW  300
#define MyInPutViewH  250
#define MyInPutViewlineW  1

@interface MyCancleSureAlertView()
@property (nonatomic,strong) CJLabel *labTitle;
@property (nonatomic,strong) UITextView *textViewInPut;
@property (nonatomic,strong) CJButton *btnSure;
@property (nonatomic,strong) CJButton *btnCancle;
@property (nonatomic,copy) OnSureClick sureBlock;
@property (nonatomic,copy) OnCancleClick cancleBlock;
@property (nonatomic,copy) NSString *strTitle;
@property (nonatomic,copy) NSString *strCancle;
@property (nonatomic,copy) NSString *strPlaceholder ;

@property (nonatomic,strong) CJLabel *labCancleTitle;
@property (nonatomic,strong) CJLabel *labCancleContent;

@end

@implementation MyCancleSureAlertView

-(instancetype)initWithTitle:(NSString *)strTitle cancleReson:(NSString *)strReson Placeholder:(NSString *)strPlaceholder ClickOnSure:(OnSureClick )sureClick ClickOnCancle:(OnCancleClick )cancleClick{
    
    
    if (self = [super init]) {
        
        self.frame = CGRectMake(0, 0, MyInPutViewW, MyInPutViewH);
        self.backgroundColor = [UIColor cjWhiteColor];
        self.sureBlock = sureClick;
        self.cancleBlock = cancleClick;
        self.strTitle = strTitle;
        self.strCancle = strReson;
        self.strPlaceholder = strPlaceholder;
        [self initWithTitleArr:strTitle];
        
    }
    return self;
}

-(void)initWithTitleArr:(NSString *)strTitle{
    
    [self addSubview:self.labCancleTitle];
    [self addSubview:self.labCancleContent];
    
    [self addSubview:self.labTitle];
    [self addSubview:self.textViewInPut];
    [self addSubview:self.btnCancle];
    [self addSubview:self.btnSure];
  
    
    self.height = self.labCancleTitle.height * 2 +self.labTitle.height + self.textViewInPut.height + LW(10) + self.btnSure.height + LW(60) + LW(20) ;
    [CJUtil getViewCutAllCornRound:self height:10];

}

- (void)btnSureAction:(UIButton *)sender{
  
    
//    if (IsNilOrNull(self.textViewInPut.text) || [self.textViewInPut.text isEqualToString:@""]) {
//        [[[AFViewShaker alloc] initWithView:self.textViewInPut] shakeWithDuration:[ShakerTime floatValue] completion:^{
//        }];
//        return;
//    }
    
    if (self.sureBlock) {
        
        self.sureBlock(self.textViewInPut.text);
    }
    WLAlertView * alerView =(WLAlertView *)[self superview];
    [alerView dismissAnimated:YES];
}

- (void)btnCancleAction:(UIButton *)sender{
    if (self.cancleBlock) {
        self.cancleBlock(self.textViewInPut.text);
    }
    WLAlertView * alerView =(WLAlertView *)[self superview];
    [alerView dismissAnimated:YES];
}



- (CJButton *)btnSure{
    if (!_btnSure) {
        _btnSure = CJButton.btnInit
        .btnFrame(CGRectMake((MyInPutViewW - 180)/5 +_btnCancle.right , _btnCancle.top ,_btnCancle.width ,_btnCancle.height))
        .btnText(@"同意")
        .btnNormalTitleColor([UIColor cjWhiteColor])
        .btnBgColor([UIColor cjMainColor])
        .btnTargetAction(self, @selector(btnSureAction:))
        .btnCornerRadius(5)
        ;
    }
    return _btnSure;
}

- (CJButton *)btnCancle{
    if (!_btnCancle) {
        _btnCancle = CJButton.btnInit
        .btnFrame(CGRectMake(((MyInPutViewW - 180)/5)*2, _textViewInPut.bottom + LW(30) ,90 , 34))
        .btnText(@"驳回")
        .btnNormalTitleColor([UIColor cjMainColor])
        .btnBgColor([UIColor cjWhiteColor])
        .btnTargetAction(self, @selector(btnCancleAction:))
        .btnCornerRadius(5)
        .btnCornerWidth(1)
        .btnCornerColor([UIColor cjMainColor])
        ;
    }
    return _btnCancle;
}

- (UITextView *)textViewInPut{
    
    if (!_textViewInPut) {
        _textViewInPut = [[UITextView alloc]initWithFrame:CGRectMake(_labCancleContent.left, _labTitle.bottom, _labCancleContent.width, LW(30))];
        _textViewInPut.font = [UIFont cjTitleFont14];
        _textViewInPut.placeholder = _strPlaceholder;
        _textViewInPut.placeholderColor = [UIColor cjSubheadTextColor];
        UIView *line = [UIView viewWithFrame:CGRectMake(_textViewInPut.left, _textViewInPut.bottom, _textViewInPut.width, MyInPutViewlineW) backgroundColor:[UIColor cjMainColor] borderColor:nil cornerRadius:0];
        [self addSubview:line];
    }
    
    return _textViewInPut;
}

- (CJLabel *)labTitle{
    
    if (!_labTitle) {
        _labTitle = CJLabel.labInit
        .labFrame(CGRectMake(_labCancleContent.left, _labCancleContent.bottom + 10, _labCancleContent.width, LW(40)))
        .labTextColor([UIColor cjMainTextColor])
        .labFontSize(18)
        .labText(_strTitle)
        ;
    }
    return _labTitle;
}


- (CJLabel *)labCancleContent{
    
    if (!_labCancleContent) {
        _labCancleContent = CJLabel.labInit
        .labFrame(CGRectMake(_labCancleTitle.left, _labCancleTitle.bottom, _labCancleTitle.width, _labCancleTitle.height))
        .labTextColor([UIColor cjMainTextColor])
        .labText(_strCancle)
        ;
        
        UIView *line = [UIView viewWithFrame:CGRectMake(_labCancleContent.left, _labCancleContent.bottom, _labCancleContent.width, MyInPutViewlineW) backgroundColor:[UIColor cjLineBackGroundColor] borderColor:nil cornerRadius:0];
        [self addSubview:line];
    }
    return _labCancleContent;
}

- (CJLabel *)labCancleTitle{
    
    if (!_labCancleTitle) {
        _labCancleTitle = CJLabel.labInit
        .labFrame(CGRectMake(CJToLeftMargin*2,25 , MyInPutViewW - 4*CJToLeftMargin, LW(40)))
        .labTextColor([UIColor cjMainTextColor])
        .labFontSize(18)
        .labText(@"取消原因")
        ;
    }
    return _labCancleTitle;
}


@end
